function CopyNLines(FileSource,FileDest,n)
 % CopyNLines(FileSource,FileDest,n) 
 % copies the first n lines in FileSource to FileDest.
 % This function is useful when dealing with large files
 
fid_s = fopen(FileSource,'r');
fid_d = fopen(FileDest,'w');
for i = 1:n
    line = fgetl(fid_s);
    if i == 1 
        fprintf(fid_d,'%s',line);
    else
        fprintf(fid_d,'\n%s',line);
    end
end
fclose(fid_d);
fclose(fid_s);